/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dpy.appmvdpy.Facades;

import com.dpy.appmvdpy.Models.UserRoles;
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 *
 * @author Lilli
 */
@Component
@Scope(value="request")
public class UsersRoleFacade extends DefaultFacade<UserRoles> {
    
    public UsersRoleFacade()
    {
       super(UserRoles.class);
    }
    
    @Override
    public void setId(UserRoles entity) {
          entity.setUserRoleId(this.getMaxId()+1);
    }
    
    public List<UserRoles> getRolesForUser(int userId)
    {
       List<UserRoles> retorno = new ArrayList<UserRoles>();
       
       for(UserRoles ur: this.listAll())
           if(ur.getUserId().getUserId() == userId)
               retorno.add(ur);
      return retorno; 
    }
            
}
